package com.stx.test.day0911;

import java.util.Arrays;

/**
 * packageName com.stx.day0911
 *
 * @author YangYi
 * @className bubbleSort
 * @date 2025/9/10
 * @description TODO
 */
public class BubbleSort {
    public static void main(String[] args) {
        // 定义一个无序的数组
        int[] arrays = {12,5,3,56,9,45,2,6,8,47};
        System.out.println(Arrays.toString(arrays));
        // 冒泡排序
        bubbleSortMethod(arrays);
    }

    /**
     * 冒泡排序
     * @param arrays
     */
    public static void bubbleSortMethod(int[] arrays){
        int temp;
        for (int i = 0; i < arrays.length -1; i++) {
            for (int j = 0; j < arrays.length -1 - i; j++) {
                if(arrays[j] > arrays[j+1]){
                    temp = arrays[j];
                    arrays[j] = arrays[j+1];
                    arrays[j+1] = temp;
                }
            }
        }
        System.out.println(Arrays.toString(arrays));
    }
}
